<?php
namespace app\cms\loglic;

class Config
{
    //模型配置
    public function fields($query=[])
    {
        $data   = config('cms');
        
        $action = DcEmpty($query['op_action'],'index');

        $fields = [
            'op_action' => [
                'type'        => 'hidden',
                'value'       => $action,
            ],
            'info_type_'.$action => [
                'type'        => 'text', 
                'value'       => $data['info_type_'.$action],
                'title'       => lang('cms_info_type'),
                'tips'        => lang('cmsTipsInfoType'),
            ],
            'page_max_'.$action => [
                'type'        => 'number', 
                'value'       => $data['page_max_'.$action],
                'required'    => true,
                'title'       => lang('cms_page_max'),
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'hr1' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'sort_index_'.$action => [
                'type'        => 'text',
                'value'       => $data['sort_index_'.$action],
                'required'    => true,
                'title'       => lang('cms_sort_index'),
                'placeholder' => 'info_id,info_order,info_views,info_create_time,info_update_time',
            ],
            'limit_index_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['limit_index_'.$action]),
                'required'    => true,
                'title'       => lang('cms_limit_index'),
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'total_index_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['total_index_'.$action]),
                'required'    => true,
                'title'       => lang('cms_total_index'),
                'placeholder' => lang('cmsTipsTotal'),
            ],
            'hr2' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'sort_category_'.$action => [
                'type'        => 'text',
                'value'       => $data['sort_category_'.$action],
                'required'    => true,
                'title'       => lang('cms_sort_category'),
                'placeholder' => 'detail_id,info_id,info_order,info_views,info_create_time,info_update_time',
            ],
            'limit_category_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['limit_category_'.$action]),
                'title'       => lang('cms_limit_category'),
                'required'    => true,
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'total_category_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['total_category_'.$action]),
                'required'    => true,
                'title'       => lang('cms_total_category'),
                'placeholder' => lang('cmsTipsTotal'),
            ],
            'hr3' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'sort_tag_'.$action => [
                'type'        => 'text',
                'value'       => $data['sort_tag_'.$action],
                'required'    => true,
                'title'       => lang('cms_sort_tag'),
                'placeholder' => 'detail_id,info_id,info_order,info_views,info_create_time,info_update_time',
            ],
            'limit_tag_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['limit_tag_'.$action]),
                'title'       => lang('cms_limit_tag'),
                'required'    => true,
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'total_tag_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['total_tag_'.$action]),
                'required'    => true,
                'title'       => lang('cms_total_tag'),
                'placeholder' => lang('cmsTipsTotal'),
            ],
            'hr4' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'sort_search_'.$action => [
                'type'        => 'text',
                'value'       => $data['sort_search_'.$action],
                'required'    => true,
                'title'       => lang('cms_sort_search'),
                'placeholder' => 'info_id,info_order,info_views,info_create_time,info_update_time',
            ],
            'limit_search_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['limit_search_'.$action]),
                'title'       => lang('cms_limit_search'),
                'required'    => true,
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'total_search_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['total_search_'.$action]),
                'required'    => true,
                'title'       => lang('cms_total_search'),
                'placeholder' => lang('cmsTipsTotal'),
            ],
            'hr5' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'sort_filter_'.$action => [
                'type'        => 'text',
                'value'       => $data['sort_filter_'.$action],
                'required'    => true,
                'title'       => lang('cms_sort_filter'),
                'placeholder' => 'info_id,info_order,info_views,info_create_time,info_update_time,cms_up',
            ],
            'limit_filter_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['limit_filter_'.$action]),
                'title'       => lang('cms_limit_filter'),
                'required'    => true,
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'total_filter_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['total_filter_'.$action]),
                'required'    => true,
                'title'       => lang('cms_total_filter'),
                'placeholder' => lang('cmsTipsTotal'),
            ],
            'hr6' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'sort_tags_'.$action => [
                'type'        => 'text',
                'value'       => $data['sort_tags_'.$action],
                'required'    => true,
                'title'       => lang('cms_sort_tags'),
                'placeholder' => 'term_id,term_count,term_order',
            ],
            'limit_tags_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['limit_tags_'.$action]),
                'title'       => lang('cms_limit_tags'),
                'required'    => true,
                'placeholder' => lang('cmsTipsLimit'),
            ],
            'total_tags_'.$action => [
                'type'        => 'number',
                'value'       => intval($data['total_tags_'.$action]),
                'required'    => true,
                'title'       => lang('cms_total_tags'),
                'placeholder' => lang('cmsTipsTotal'),
            ],
        ];
        foreach($fields as $key=>$value){
            if(!isset($value['title'])){
                $fields[$key]['title'] = lang('cms_'.$key);
            }
        }
        //扩展表单字段（手动加载）
        if($customs = cmsMetaList('config', $action)){
            $fields['hr'] = [
                'type'        => 'html',
                'value'       => '<hr>',
            ];
            $fields = array_merge($fields, DcFields($customs, $data) );
        }
        return DcFormItems($fields);
    }
    
    //初始配置
    public function fieldsSystem($query=[])
    {
        $themes = DcThemeOption('cms');

        $fields = [
            'op_action' => [
                'type'        => 'hidden',
                'value'       => 'system',
            ],
            'theme' => [
                'type'   =>'select', 
                'value'  => config('cms.theme'), 
                'option' => $themes,
            ],
            'theme_wap' => [
                'type'   => 'select',
                'value'  => config('cms.theme_wap'),
                'option' => $themes,
            ],
            'slug_first' => [
                'type'       => 'select',
                'value'      => config('cms.slug_first'),
                'option'     => [0=>lang('close'),1=>lang('open')],
            ],
            'term_tpl' => [
                'type'       => 'select',
                'value'      => config('cms.term_tpl'),
                'option'     => [0=>lang('close'),1=>lang('open')],
                'tips'       => lang('cmsTipsTermTpl'),
            ],
            'action_name' => [
                'type'       => 'text',
                'value'      => config('cms.action_name'),
                'tips'        => lang('cmsTipsActionName'),
            ],
            'baidu_api' => [
                'type'       => 'text',
                'value'      => config('cms.baidu_api'),
                'tips'       => lang('cmsTipsBaiduApi'),
            ],
            'post_pwd' => [
                'type'       => 'text',
                'value'      => config('cms.post_pwd'),
                'tips'       => lang('cmsTipsPostPwd'),
            ],
            'label_strip' => [
                'type'       => 'text',
                'value'      => config('cms.label_strip'),
                'tips'       => lang('cmsTipsLabelStrip'),
            ],
            'hr_1' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'search_like' => [
                'type'       => 'select',
                'value'      => config('cms.search_like'),
                'option'     => [0=>lang('close'),1=>lang('open')],
                'tips'        => lang('cmsTipsSearchLike'),
            ],
            'search_field' => [
                'type'        => 'text',
                'required'    => true,
                'value'       => config('cms.search_field'),
                'tips'        => lang('cmsTipsSearchField'),
            ],
            'search_list' => [
                'type'        => 'text',
                'value'       => config('cms.search_list'),
                'tips'        => lang('cmsTipsSearchList'),
            ],
            'search_interval' => [
                'type'        => 'number',
                'value'       => intval(config('cms.search_interval')),
                'tips'        => lang('cmsTipsSearchInterval'),
            ],
            'search_hot' => [
                'type'        => 'text',
                'value'       => config('cms.search_hot'),
                'rows'        => 3,
                'tips'        => lang('cmsTipsSearchHot'),
            ],
            'hr_2' => [
                'type'        => 'html',
                'value'       => '<hr>',
            ],
            'white_ip' => [
                'type'        => 'textarea',
                'value'       => config('cms.white_ip'),
                'tips'        => lang('cmsTipsWhiteIp'),
                'rows'        => 2,
            ],
            'black_ip' => [
                'type'        => 'textarea',
                'value'       => config('cms.black_ip'),
                'tips'        => lang('cmsTipsBlackIp'),
                'rows'        => 2,
            ],
            'close_useragent' => [
                'type'        => 'textarea',
                'value'       => config('cms.close_useragent'),
                'tips'        => lang('cmsTipsCloseUseragent'),
                'rows'        => 2,
            ],
            'request_max' => [
                'type'        => 'number',
                'value'       => intval(config('cms.request_max')),
                'tips'        => lang('cmsTipsRequestMax'),
            ],
        ];
        foreach($fields as $key=>$value){
            if(!isset($value['title'])){
                $fields[$key]['title'] = lang('cms_'.$key);
            }
        }
        //扩展表单字段（自动加载）
        if($customs = cmsMetaList('config', 'system')){
            $fields['hr'] = [
                'type'        => 'html',
                'value'       => '<hr>',
            ];
            $fields = array_merge($fields, DcFields($customs, config('cms')) );
        }
        //返回结果
        return DcFormItems($fields);
    }
}